package com.cykj.common.dto;

import lombok.Data;

@Data
public class ResponseDTO {
    private Integer code;
    private String msg;
    private Object data;

    public ResponseDTO(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseDTO(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private static final Integer SUCCESS_CODE = 200;
    private static final Integer ERROR_CODE = 500;
    private static final Integer TOKEN_ERROR_CODE = 401;
    private static final Integer CODE_ERROR_CODE = 4001;

    /**
    * @Description: 请求成功，未携带参数
    * @Param: []
    * @return: com.cykj.common.dto.ResponseDTO
    */
    public static ResponseDTO success(){
        return new ResponseDTO(SUCCESS_CODE,"success");
    }

    /**
     * @Description: 请求成功，携带数据返回
     * @Param: [data]
     * @return: com.cykj.dto.ResponseDTO
     */
    public static ResponseDTO success(Object data) {
        return new ResponseDTO(SUCCESS_CODE, "success", data);
    }

    /**
     * @Description: 请求成功，携带影响行数返回
     * @Param: [lineCount]
     * @return: com.cykj.dto.ResponseDTO
     */
    public static ResponseDTO success(Integer lineCount) {
        return new ResponseDTO(SUCCESS_CODE, "effect line", lineCount);
    }

    /**
     * @Description: 请求失败，携带原因返回
     * @Param: [msg]
     * @return: com.cykj.dto.ResponseDTO
     */
    public static ResponseDTO error(String msg) {
        return new ResponseDTO(ERROR_CODE, msg);
    }

    /**
     * @Description: 请求失败
     * @Param: []
     * @return: com.cykj.dto.ResponseDTO
     */
    public static ResponseDTO error() {
        return new ResponseDTO(ERROR_CODE, "error");
    }

    /**
     * @Description: 请求失败，携带原因返回,自定义状态码
     * @Param: [msg]
     * @return: com.cykj.dto.ResponseDTO
     */
    public static ResponseDTO error(Integer code,String msg) {
        return new ResponseDTO(code, msg);
    }


    /**
     * @Description: token错误（未携带token，或token过期）
     * @Param: []
     * @return: com.cykj.dto.ResponseDTO
     */
    public static ResponseDTO tokenError(String msg) {
        return new ResponseDTO(TOKEN_ERROR_CODE, msg);
    }

    /**
     * @Description: 验证码错误（验证码错误，或验证码过期）
     * @Param: []
     * @return: com.cykj.dto.ResponseDTO
     */
    public static ResponseDTO codeError(String msg) {return new ResponseDTO(CODE_ERROR_CODE, msg);}
}